<template>
  <div class="cate">
    全部类别
    <div class="cate-list" @mouseleave="hideOneClass">
      <div
        class="cate-list-item"
        :class="{ active: showOneClass == index }"
        @mouseenter="oneClassHover(index)"
        v-for="(item, index) in classList"
        :key="index"
        @click="toClassPage(item.id, item.name)"
      >
        {{ item.name }}<icon name="iconxiangyoubeifen16" size="14" />
      </div>
      <div v-if="showOneClass !== null" class="two-class-box">
        <div
          class="cate-list-two-item"
          v-for="(item, index) in classList[showOneClass].category_two"
          :key="index"
        >
          <div class="tit">{{ item.name }}</div>
          <div class="cate-list-three">
            <div
              @click="toClassPage(cate.id, cate.name)"
              class="cate-list-three-item"
              v-for="(cate, i) in item.category_three"
              :key="i"
            >
              <img :src="cate.img_path" alt="" />
              {{ cate.name }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from "@/api";
export default {
  data() {
    return {
      classList: [],
      showOneClass: null,
    };
  },
  created() {
    this.getClassList();
  },
  methods: {
    async getClassList() {
      let classList = await api.CLASS_LIST();
      this.classList = classList;
    },
    oneClassHover(index) {
      this.showOneClass = index;
    },
    hideOneClass() {
      this.showOneClass = null;
    },
    toClassPage(id, name) {
      this.$router.push({
        path: "/goods/search",
        query: Object.assign({}, this.$route.query, {
          appoint_id: id,
          appoint_name: name,
        }),
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.cate {
  width: 160px;
  height: 100%;
  background: #d52c1a;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: 5px 5px 0px 0px;
  position: relative;
  z-index: 10;
  &:hover {
    .cate-list {
      height: auto;
      transform: scaleY(1);
    }
  }
  .cate-list {
    position: relative;
    border-radius: 5px;
    width: 100%;
    height: 0;
    position: absolute;
    left: 0;
    top: 100%;
    padding-top: 20px;
    color: #666666;
    transform: scaleY(0);
    transform-origin: 0 0;
    transition: transform 0.2s;
    z-index: -1;
    .two-class-box {
      position: absolute;
      left: 100%;
      margin-left: 0px;
      top: 20px;
      bottom: 0px;
      width: 700px;
      background: #fff;
      padding: 5px;
      border-radius: 0 10px 10px 0;
      overflow-y: auto;
      &::-webkit-scrollbar {
        width: 5px;
        height: 5px;
        background-color: transparent;
      }

      /*定义滚动条轨道 内阴影+圆角*/
      &::-webkit-scrollbar-track {
        border-radius: 10px;
        background-color: transparent;
      }

      /*定义滑块 内阴影+圆角*/
      &::-webkit-scrollbar-thumb {
        border-radius: 10px;
        background-color: #999999;
      }
      .cate-list-two-item {
        .tit {
          font-size: 16px;
        }
        .cate-list-three {
          padding: 5px;
          margin-bottom: 10px;
          .cate-list-three-item {
            margin: 0 10px 10px 0;
            display: inline-flex;
            flex-direction: column;
            align-items: center;
            font-size: 12px;
            cursor: pointer;
            img {
              width: 60px;
              height: 60px;
            }
          }
        }
      }
    }
    .cate-list-item {
      background: white;
      font-size: 14px;
      line-height: 16px;
      padding: 10px 20px 10px 30px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      cursor: pointer;
      position: relative;
      &:first-child {
        border-radius: 5px 5px 0 0;
      }
      &:last-child {
        border-radius: 0 0 5px 5px;
      }
      &:hover {
        color: #d52c1a;
        .sub-cate {
          width: 120px;
        }
      }
      &.active {
        color: #d52c1a;
      }
      .sub-cate {
        width: 0;
        position: absolute;
        transition: width 0.2s;
        top: 0;
        left: 100%;
        background: #fff;
        border-radius: 5px;
        color: #666666;
        overflow: hidden;
        .sub-cate-item {
          width: 80px;
          padding: 10px 20px;
          line-height: 16px;
          &:hover {
            color: #d52c1a;
          }
        }
      }
    }
  }
}
</style>
